/logscale false def
/lpmin 1e-05 log def
/DataVisible  [ true true true true] def
/DataTitles   [ false false false false ] def
/min { 2 copy gt { exch } if pop } bind def
/max { 2 copy lt { exch } if pop } bind def
/box { %size x y box - draws box centered on x,y
   2 index 0.5 mul sub            % x -= 0.5
   exch 2 index 0.5 mul sub exch  % y -= 0.5
   3 -1 roll dup rectfill
} bind def
/ubox {
   logscale {
      log dup add lpmin div 1 exch sub dup 0 lt { pop 0 } if
   } if
   3 1 roll
   exch len exch sub 1 add box
} bind def
/lbox {
   3 1 roll
   len exch sub 1 add box
} bind def
/drawseq { % print sequence along all 4 sides
[ [0.7 -0.3 0 ]
  [0.7 0.7 len add 0]
  [-0.3 len sub -0.4 -90]
  [-0.3 len sub 0.7 len add -90]
] {
   gsave
    aload pop rotate translate
    0 1 len 1 sub {
     dup 0 moveto
     sequence exch 1 getinterval
     show
    } for
   grestore
  } forall
} bind def
/drawgrid{
  gsave
  0.5 dup translate
  0.01 setlinewidth
  len log 0.9 sub cvi 10 exch exp  % grid spacing
  dup 1 gt {
     dup dup 20 div dup 2 array astore exch 40 div setdash
  } { [0.3 0.7] 0.1 setdash } ifelse
  0 exch len {
     dup dup
     0 moveto
     len lineto
     dup
     len exch sub 0 exch moveto
     len exch len exch sub lineto
     stroke
  } for
  [] 0 setdash
  0.04 setlinewidth
  % draw strand separators if required
  currentdict /nicks known {
    gsave
    % draw lines in red color
    0 1 1 sethsbcolor
    % draw with line thickness of 0.2
    0.2 setlinewidth
    nicks
    { 1 sub
    dup dup -1 moveto len 1 add lineto
    len exch sub dup
    -1 exch moveto len 1 add exch lineto
    stroke
    } forall
    grestore
  } if
  % draw diagonal
  0 len moveto len 0 lineto stroke
  grestore
} bind def
/drawTitle {
  currentdict /DPtitle known {
    % center title text
    /Helvetica findfont 10 scalefont setfont
    360 705 moveto DPtitle dup stringwidth pop 2 div neg 0 rmoveto show
  } if
} bind def
/prepareCoords {
  0 1 3 {
    % check whether we want to display current data
    dup DataVisible exch get
    {
      % check whether we've actually got some data
      DataSource exch get dup currentdict exch known {
        % data source s_j is present, so find length of array
        currentdict exch get length 
      } { pop 0 } ifelse
    } if
  } for
  exch dup 5 -1 roll add 4 -1 roll dup 5 1 roll 4 -1 roll add max
  len add 3 add 700 exch div dup scale
  exch 1 add exch 1 add translate
} bind def
